package com.shimi.erp.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.shimi.erp.domain.PageHelper;
import com.shimi.erp.domain.University;
import com.shimi.erp.service.UniversityService;
import com.shimi.erp.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("university")
public class UniversityController {

    @Autowired
    private UniversityService universityService;

    @PostMapping("findAll")
    @ResponseBody
    public JSONObject findAll(@RequestBody JSONObject param){

        JSONObject re;

        PageHelper pageHelper = param.getObject("page", PageHelper.class);
        University university = param.getObject("university", University.class);
        re = JsonUtil.createOKJSON(universityService.findAll(university, pageHelper));

        return re;
    }

    @PostMapping("addOne")
    @ResponseBody
    public JSONObject addOne(@RequestBody University university){

        JSONObject re;

        re = JsonUtil.createOKJSON(universityService.addOne(university));

        return re;
    }

    @PostMapping("updateOne")
    @ResponseBody
    public JSONObject updateOne(@RequestBody University university){

        JSONObject re;

        re = JsonUtil.createOKJSON(universityService.updateOne(university));

        return re;
    }
}
